home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / managers / layoutClasses / PriorityQueue.as
Encoding:
Text File  |  2008-10-29  |  5.9 KB  |  210 lines

  1. package mx.managers.layoutClasses
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import mx.core.IChildList;
  6.    import mx.core.IRawChildrenContainer;
  7.    import mx.core.mx_internal;
  8.    import mx.managers.ILayoutManagerClient;
  9.    
  10.    use namespace mx_internal;
  11.    
  12.    public class PriorityQueue
  13.    {
  14.       mx_internal static const VERSION:String = "3.0.0.0";
  15.       
  16.       private var maxPriority:int = -1;
  17.       
  18.       private var arrayOfArrays:Array;
  19.       
  20.       private var minPriority:int = 0;
  21.       
  22.       public function PriorityQueue()
  23.       {
  24.          arrayOfArrays = [];
  25.          super();
  26.       }
  27.       
  28.       public function addObject(param1:Object, param2:int) : void
  29.       {
  30.          if(!arrayOfArrays[param2])
  31.          {
  32.             arrayOfArrays[param2] = [];
  33.          }
  34.          arrayOfArrays[param2].push(param1);
  35.          if(maxPriority < minPriority)
  36.          {
  37.             minPriority = maxPriority = param2;
  38.          }
  39.          else
  40.          {
  41.             if(param2 < minPriority)
  42.             {
  43.                minPriority = param2;
  44.             }
  45.             if(param2 > maxPriority)
  46.             {
  47.                maxPriority = param2;
  48.             }
  49.          }
  50.       }
  51.       
  52.       public function removeSmallest() : Object
  53.       {
  54.          var _loc1_:Object = null;
  55.          if(minPriority <= maxPriority)
  56.          {
  57.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  58.             {
  59.                ++minPriority;
  60.                if(minPriority > maxPriority)
  61.                {
  62.                   return null;
  63.                }
  64.             }
  65.             _loc1_ = arrayOfArrays[minPriority].shift();
  66.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  67.             {
  68.                ++minPriority;
  69.                if(minPriority > maxPriority)
  70.                {
  71.                   break;
  72.                }
  73.             }
  74.          }
  75.          return _loc1_;
  76.       }
  77.       
  78.       public function removeLargestChild(param1:ILayoutManagerClient) : Object
  79.       {
  80.          var _loc5_:int = 0;
  81.          var _loc2_:Object = null;
  82.          var _loc3_:int = maxPriority;
  83.          var _loc4_:int = int(param1.nestLevel);
  84.          while(_loc4_ <= _loc3_)
  85.          {
  86.             if(Boolean(arrayOfArrays[_loc3_]) && arrayOfArrays[_loc3_].length > 0)
  87.             {
  88.                _loc5_ = 0;
  89.                while(_loc5_ < arrayOfArrays[_loc3_].length)
  90.                {
  91.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc5_]))
  92.                   {
  93.                      _loc2_ = arrayOfArrays[_loc3_][_loc5_];
  94.                      arrayOfArrays[_loc3_].splice(_loc5_,1);
  95.                      return _loc2_;
  96.                   }
  97.                   _loc5_++;
  98.                }
  99.                _loc3_--;
  100.             }
  101.             else
  102.             {
  103.                if(_loc3_ == maxPriority)
  104.                {
  105.                   --maxPriority;
  106.                }
  107.                _loc3_--;
  108.                if(_loc3_ < _loc4_)
  109.                {
  110.                   break;
  111.                }
  112.             }
  113.          }
  114.          return _loc2_;
  115.       }
  116.       
  117.       public function isEmpty() : Boolean
  118.       {
  119.          return minPriority > maxPriority;
  120.       }
  121.       
  122.       public function removeLargest() : Object
  123.       {
  124.          var _loc1_:Object = null;
  125.          if(minPriority <= maxPriority)
  126.          {
  127.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  128.             {
  129.                --maxPriority;
  130.                if(maxPriority < minPriority)
  131.                {
  132.                   return null;
  133.                }
  134.             }
  135.             _loc1_ = arrayOfArrays[maxPriority].shift();
  136.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  137.             {
  138.                --maxPriority;
  139.                if(maxPriority < minPriority)
  140.                {
  141.                   break;
  142.                }
  143.             }
  144.          }
  145.          return _loc1_;
  146.       }
  147.       
  148.       public function removeSmallestChild(param1:ILayoutManagerClient) : Object
  149.       {
  150.          var _loc4_:int = 0;
  151.          var _loc2_:Object = null;
  152.          var _loc3_:int = int(param1.nestLevel);
  153.          while(_loc3_ <= maxPriority)
  154.          {
  155.             if(Boolean(arrayOfArrays[_loc3_]) && arrayOfArrays[_loc3_].length > 0)
  156.             {
  157.                _loc4_ = 0;
  158.                while(_loc4_ < arrayOfArrays[_loc3_].length)
  159.                {
  160.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc4_]))
  161.                   {
  162.                      _loc2_ = arrayOfArrays[_loc3_][_loc4_];
  163.                      arrayOfArrays[_loc3_].splice(_loc4_,1);
  164.                      return _loc2_;
  165.                   }
  166.                   _loc4_++;
  167.                }
  168.                _loc3_++;
  169.             }
  170.             else
  171.             {
  172.                if(_loc3_ == minPriority)
  173.                {
  174.                   ++minPriority;
  175.                }
  176.                _loc3_++;
  177.                if(_loc3_ > maxPriority)
  178.                {
  179.                   break;
  180.                }
  181.             }
  182.          }
  183.          return _loc2_;
  184.       }
  185.       
  186.       public function removeAll() : void
  187.       {
  188.          arrayOfArrays.splice(0);
  189.          minPriority = 0;
  190.          maxPriority = -1;
  191.       }
  192.       
  193.       private function contains(param1:DisplayObject, param2:DisplayObject) : Boolean
  194.       {
  195.          var _loc3_:IChildList = null;
  196.          if(param1 is IRawChildrenContainer)
  197.          {
  198.             _loc3_ = IRawChildrenContainer(param1).rawChildren;
  199.             return _loc3_.contains(param2);
  200.          }
  201.          if(param1 is DisplayObjectContainer)
  202.          {
  203.             return DisplayObjectContainer(param1).contains(param2);
  204.          }
  205.          return param1 == param2;
  206.       }
  207.    }
  208. }
  209.  
  210.